package com.nine.shop.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nine.shop.mapper.GoodsMapper;
import com.nine.shop.model.Goods;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hty
 * Create on 2019/8/17
 */
@Service
public class GoodsService extends ServiceImpl<GoodsMapper, Goods> {


    /**
     * 分页显示不同类型商品
     * @param current 当前页码
     * @param size 每页大小
     * @param typeId 类型ID
     */
    public IPage<Goods> findByTypeIdPage(Integer current,Integer size,Integer typeId){
        return baseMapper.findByTypeIdPage(new Page<>(current,size),typeId);
    }
    /**
     *根据商品ID查询详细信息
     * @param goodsid 商品ID
     *
     */
    public Goods findByGoodsId(Integer goodsid) {
        return baseMapper.findById(goodsid);
    }


    /**
     *@Description 获取库存数量
     *@Param [goodsId]
     *@Return int
     *@Author wangcong
     *@Date 2019/8/25
     *@Time 11:59
     */
    public int getStock(int goodsId){
        int num =baseMapper.selectById(goodsId).getCount();
        return num;
    }

    /**
    *@Description 分页查询所有商品
    *@Param [current, size]
    *@Return com.baomidou.mybatisplus.core.metadata.IPage<com.nine.shop.model.Cart>
    *@Author wangcong
    *@Date 2019/8/27
    *@Time 12:14
    */
    public IPage<Goods> searchByIdPage(Integer current, Integer size){
        return baseMapper.selectPage(new Page<>(current,size),new QueryWrapper<Goods>().orderByAsc("id"));
    }

    /**
    *@Description 模糊查询
    *@Param [goodsName]
    *@Return java.util.List<com.nine.shop.model.Goods>
    *@Author wangcong
    *@Date 2019/8/28
    *@Time 9:47
    */
    public List<Goods> findByGoodsName(String goodsName){
        return baseMapper.selectList(new QueryWrapper<Goods>().like("title",goodsName));
    }

    /**
    *@Description 获取所有商品
    *@Param [current, size]
    *@Return com.baomidou.mybatisplus.core.metadata.IPage<com.nine.shop.model.Goods>
    *@Author wangcong
    *@Date 2019/8/28
    *@Time 11:31
    */
    public IPage<Goods> findGoodsPage(Integer current, Integer size){
        return baseMapper.findGoodsPage(new Page<>(current,size));
    }

}
